﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ScFramework.Core;
using UnityEngine.UI;

public class KeyChangeUI : LogicModuleBase<UIManager, InputManager>, ICombineSubUI
{
    private SFuncBaseVEx func;
    GameObject target;
    bool isOpen;

    public void InitGameobject(List<GameObject> obj)
    {
        target = obj.Find(s => s.name == "KeyChangeUI");
        isOpen = false;
    }
    [RegisterEvent( CombineUIEvent.KeyChangedBefore)]
    void Open(SFuncBaseVEx x)
    {
        SysModule.Open(target.name);
        func = x;
        isOpen = true;
    }
    public override void Update()
    {
        base.Update();
        if (isOpen)
        {
            foreach (KeyCode k in System.Enum.GetValues(typeof(KeyCode)))
            {
                if (SysModule1.GetKeyDown(k) == false)
                {
                    continue;
                }
                if (SysModule1.UseableKeys.Contains(k))
                {
                    func.Key = k;
                    Dispatch(CombineUIEvent.KeyChanged);
                }
                else
                {
                    SysModule.Open("DialogWindowUI", 5, args: new DialogWindowUI.DialogWindowUIArg
     ("注意", $"设置的按键{k}不在可用范围内", null, "确定", () => { }));
                }
                Dispatch(CombineUIEvent.KeyChanged);
                SysModule.Close("KeyChangeUI");
                isOpen = false;
            }
        }
    }
}
